package com.cqs.leetcode;

/**
 * Created by cqs on 2018/4/7.
 */
public class RepeatedStringMatch {

    public int repeatedStringMatch(String A, String B) {
        if (A == null || B == null) return -1;
        if ("".equals(B)) return 1;
        if ("".equals(A)) return -1;
        if (A.contains(B)) return 1;
        int times = (int) (Math.ceil(1.0 * B.length() / A.length())) + 1;
        StringBuilder  sb = new StringBuilder(A);
        for (int i = 2; i <= times; ++i) {
            sb.append(A);
            if (sb.toString().contains(B)) return i;
        }
        return -1;
    }

    public static void main(String[] args) {
        RepeatedStringMatch r = new RepeatedStringMatch();
        String A = "a";
        String B = "a";
        System.out.println(B.length()*1.0/A.length());
        int i = r.repeatedStringMatch(A, B);
        System.out.println(i);
    }
}
